package qianting.news.common.entity;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import qianting.news.common.enums.AppHttpCodeEnum;

/**
 * @program: big-event
 * @des:
 * @author: tzx
 * @create: 2023-11-02 13:12
 */

@Data
@Slf4j
public class State {

    private int code; // 200是正常，非200表示异常
    private String msg;
    private Object data;

    public static State succ(String msg) {
        return succ(200, msg, null);
    }

    public static State succ(AppHttpCodeEnum codeEnum) {
        return succ(200, codeEnum.getErrorMessage(), null);
    }

    public static State succ(Object data) {
        return succ(200, "操作成功", data);
    }

    public static State succ() {
        return succ(200, "操作成功", null);
    }

    public static State succ(String msg,Object data) {
        return succ(200, msg, data);
    }

    public static State succ(int code, String msg, Object data) {
        State r = new State();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static State fail(String msg) {
        return fail(400, msg, null);
    }

    public static State fail(AppHttpCodeEnum codeEnum) {
        return fail(400, codeEnum.getErrorMessage(), null);
    }

    public static State fail(String msg, Object data) {
        return fail(400, msg, data);
    }

    public static State fail(int code,String msg) {
        return fail(400, msg, null);
    }

    public static State fail(int code, String msg, Object data) {
        State r = new State();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        log.error(msg);
        return r;
    }

}
